/**
 * 影片动画，序列帧在一张图片上，继承自Bitmap
 * @param bitmapData 序列图片
 * @param width 此影片的宽
 * @param height 此影片的高
 * @returns {MovieClip}
 */
MovieClip = function(bitmapData,width,height,frameRate)
{
	Bitmap.call(this,bitmapData);
	this.frameRate = frameRate?frameRate:1 ;
	this.setWidth(width) ;
	this.setHeight(height) ;

	this._isPlay=false; //是否在自动播放状态
	this._currentFrame =1 ; //当前播放到了第几帧，1为第一帧
	this._totalFrames = 0 ; //总共的帧数
	this._frameArray =[]; //所有的帧
	this._tempFrameRate = 0 ;
};
FLASH.extend(MovieClip,Bitmap); //继承自Bitmap

//==========getter/settter=========================================
MovieClip.prototype.isPlay = function(){ return  this._isPlay ;};
MovieClip.prototype.getCurrentFrame = function(){ return this._currentFrame ;};
MovieClip.prototype.getTotalFrames = function(){ return this._totalFrames ;};
//========================================================

/**
 * 重写设置图片数据源
 */
MovieClip.prototype.setBitmapData = function( bitmapData ) {
	this._bitmapData = bitmapData ;
};
/**
 * 添加帧
 * @param rect 此帧 在图片上的矩形位置
 * @returns {MovieClip} 返回当前对象，可以做链式添加
 */
MovieClip.prototype.addFrame = function(rect)
{
	this._totalFrames++;
	this._frameArray.push(rect);
	return this;	
};

/**
 * 一次设置所有的帧动作
 * @param rectArray
 */
MovieClip.prototype.setFrames=function(rectArray)
{
	this._frameArray = rectArray ;
	this._totalFrames = rectArray.length;
};

/**
 * 输出
 * @param globalAlpha 
 * @param context
 */
MovieClip.prototype._draw =function( globalAlpha,context )
{
	if(this._totalFrames>0 ){
		if(this._currentFrame>this._totalFrames){
			this._currentFrame = 1 ;	
		};
		this._currentRect= this._frameArray[this._currentFrame-1] ;
		Bitmap.prototype._draw.call(this , globalAlpha , context) ;
		if(this._isPlay){
			this._tempFrameRate++;
			if(this._tempFrameRate>=this.frameRate){
				this._tempFrameRate=0;
				this._currentFrame++;
			}
		}
	}
	
};
/**
 * 播放
 */
MovieClip.prototype.play = function(){
	this._isPlay = true ;	
};
/**
 * 停止
 */
MovieClip.prototype.stop = function(){
	this._isPlay = false ;	
};
/**
 * 到某一帧停止
 * @param frame
 */
MovieClip.prototype.gotoAndStop = function(frame){
	if(frame<1) frame=1 ;
	else if(frame>this._totalFrames) frame=this._totalFrames;
	
	this._currentFrame = frame ;
	this._isPlay = false ;
};
/**
 * 到某一帧播放
 * @param frame
 */
MovieClip.prototype.gotoAndPlay = function(frame){
	if(frame<1) frame=1 ;
	else if(frame>this._totalFrames) frame=this._totalFrames;
	
	this._currentFrame = frame ;
	this._isPlay = true ;
};
/**
 * 播放到下一帧 停止
 */
MovieClip.prototype.nextFrame = function(){
	if(this._currentFrame==this._totalFrames) this._currentFrame=1;
	else this._currentFrame++;
};
/**
 * 转到上一帧停止
 */
MovieClip.prototype.prevFrame = function(){
	if(this._currentFrame==1) this._currentFrame=this._totalFrames;
	else this._currentFrame--;
};
/**
 * 释放资源
 */
MovieClip.prototype.dispose = function()
{
	Bitmap.prototype.dispose.call(this);
	this._bitmapData = null ; 
	this._frameArray =null; //所有的帧
};